def method():
    _, n = map(int, input().split(' '))
    s = input()
    for _ in range(n):
        op = input()

        Iindex = s.find('I')
        if op == 'backspace':
            if Iindex-1 >= 0 and Iindex+1 < len(s) and s[Iindex-1] == '(' and s[Iindex+1] == ')':
                s = s[:Iindex-1] + 'I' + s[Iindex+2:]
            elif Iindex-1 >= 0:
                s = s[:Iindex-1] + 'I' + s[Iindex+1:]
        elif op == 'delete':
            if Iindex+1 < len(s):
                s = s[:Iindex] + 'I' + s[Iindex+2:]
        elif op == '<-':
            if Iindex-1 >= 0:
                s = s[:Iindex-1] + 'I' + s[Iindex-1] + s[Iindex+1:]
        elif op == '->':
            if Iindex+1 < len(s):
                s = s[:Iindex] + s[Iindex+1] + 'I' + s[Iindex+2:]
    return s

if __name__ == '__main__':
    s = method()
    print(s)
